package sum.book.auth.api.properties;

import lombok.Data;
import org.apache.commons.codec.binary.Base64;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;
import sum.book.common.core.constant.CommonConstants;

@Data
@Configuration
@EnableConfigurationProperties({Oauth2Properties.class})
@ConfigurationProperties(prefix = "oauth.token")
public class Oauth2Properties {
    /**
     * clientId
     */
    private String clientId;
    /**
     * clientSecret
     */
    private String clientSecret;

    public String basicAuth() {
        Assert.notNull(this.clientId, "oauth.token.clientId不能为空");
        Assert.notNull(this.clientSecret, "oauth.token.clientSecret不能为空");
        String auth = this.clientId + ":" + this.clientSecret;
        return "Basic " + Base64.encodeBase64String(auth.getBytes(CommonConstants.DEFAULT_CHARSET));
    }

}



